home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / ULARN.ARJ / ULARN.TAR / ularn / diag.c < prev    next >
C/C++ Source or Header  |  1989-10-25  |  12KB  |  449 lines

  1. /*    diag.c    */
  2. #include "header.h"
  3.  
  4. extern long int initialtime;
  5. extern int rmst,maxitm,lasttime;
  6. extern char nosignal;
  7.  
  8. char *cdef[] = {
  9.     "STRENGTH", "INTELLIGENCE", "WISDOM", "CONSTITUTION", "DEXTERITY",
  10.     "CHARISMA", "HPMAX", "HP", "GOLD", "EXPERIENCE",
  11.     "LEVEL", "REGEN", "WCLASS", "AC", "BANKACCOUNT",
  12.     "SPELLMAX", "SPELLS", "ENERGY", "ECOUNTER", "MOREDEFENSES",
  13.     "WEAR", "PROTECTIONTIME", "WIELD", "AMULET", "REGENCOUNTER",
  14.     "MOREDAM", "DEXCOUNT", "STRCOUNT", "BLINDCOUNT", "CAVELEVEL",
  15.     "CONFUSE", "ALTPRO", "HERO", "CHARMCOUNT", "INVISIBILITY",
  16.     "CANCELLATION", "HASTESELF", "EYEOFLARN", "AGGRAVATE ", "GLOBE",
  17.     "TELEFLAG", "SLAYING", "NEGATESPIRIT", "SCAREMONST ", "AWARENESS",
  18.     "HOLDMONST", "TIMESTOP", "HASTEMONST", "CUBEofUNDEAD", "GIANTSTR",
  19.     "FIRERESISTANCE", "BESSMANN", "NOTHEFT", "HARDGAME", "",
  20.     "", "", "", "", "",
  21.     "LANCEDEATH", "SPIRITPRO", "UNDEADPRO", "SHIELD ", "STEALTH",
  22.     "ITCHING", "LAUGHING", "DRAINSTRENGTH", "CLUMSINESS", "INFEEBLEMENT",
  23.     "HALFDAM", "SEEINVISIBLE", "FILLROOM", "", "SPHCAST",
  24.     "WTW", "STREXTRA", "TMP", "LIFEPROT", "ORB",
  25.     "ELVUP", "ELVDOWN", "HAND", "CUBEUNDEAD", "DRAGSLAY", 
  26.     "NEGATE", "URN", "LAMP", "TALISMAN", "WAND", 
  27.     "STAFF", "DEVICE", "SLASH", "ELVEN", "VORP", 
  28.     "SLAY", "PAD", "COKED", "", "" };
  29.  
  30. char *ivendef[] = {
  31.     "",
  32.     "OALTAR", "OTHRONE", "OORB", "OPIT", "OSTAIRSUP",
  33.     "OELEVATORUP", "OFOUNTAIN", "OSTATUE", "OTELEPORTER", "OSCHOOL",
  34.     "OMIRROR", "ODNDSTORE", "OSTAIRSDOWN", "OELEVATORDOWN", "OBANK2",
  35.     "OBANK", "ODEADFOUNTAIN", "OGOLDPILE", "OOPENDOOR", "OCLOSEDDOOR",
  36.     "OWALL", "OTRAPARROW", "OTRAPARROWIV", "OLARNEYE", "OPLATE",
  37.     "OCHAIN", "OLEATHER", "ORING", "OSTUDLEATHER", "OSPLINT",
  38.     "OPLATEARMOR", "OSSPLATE", "OSHIELD", "OSWORDofSLASHING", "OHAMMER",
  39.     "OSWORD", "O2SWORD", "OSPEAR", "ODAGGER", "OBATTLEAXE",
  40.     "OLONGSWORD", "OFLAIL", "OLANCE", "ORINGOFEXTRA", "OREGENRING",
  41.     "OPROTRING", "OENERGYRING", "ODEXRING", "OSTRRING", "OCLEVERRING",
  42.     "ODAMRING", "OBELT", "OSCROLL", "OPOTION", "OBOOK",
  43.     "OCHEST", "OAMULET", "OORBOFDRAGON", "OSPIRITSCARAB", "OCUBEofUNDEAD",
  44.     "ONOTHEFT", "ODIAMOND", "ORUBY", "OEMERALD", "OSAPPHIRE",
  45.     "OENTRANCE", "OVOLDOWN", "OVOLUP", "OHOME", "OMAXGOLD",
  46.     "OKGOLD", "ODGOLD", "OIVDARTRAP", "ODARTRAP", "OTRAPDOOR",
  47.     "OIVTRAPDOOR", "OTRADEPOST", "OIVTELETRAP", "ODEADTHRONE", "OANNIHILATION",
  48.     "OTHRONE2", "OLRS", "OCOOKIE", "OURN", "OBRASSLAMP",
  49.     "OHANDofFEAR", "OSPHTALISMAN", "OWWAND", "OPSTAFF", "OVORPAL",
  50.     "OSLAYER", "OELVENCHAIN", "OSPEED", "OACID", "OHASH",
  51.     "OSHROOMS", "OCOKE", "OPAD", "" };
  52.  
  53.  
  54. /*
  55.     ***************************
  56.     DIAG -- dungeon diagnostics
  57.     ***************************
  58.  
  59.     print out data for debugging
  60.  */
  61.  
  62. FILE *dfile;
  63.  
  64. diag()
  65. {
  66.     register int    i, j;
  67.  
  68.     if ((dfile = fopen(diagfile, "w")) == NULL) {
  69.         return(0);
  70.     }
  71.     lprcat("\nDiagnosing . . .\n");
  72.     lflush();
  73.  
  74.     fprintf(dfile,"\n-------- Beginning of DIAG diagnostics ---------\n\n");
  75.  
  76.     fprintf(dfile, "Hit points: %2ld(%2ld)\n", c[HP], c[HPMAX]);
  77.  
  78.     fprintf(dfile, "gold: %ld  Experience: %ld  Character level: %d  Level in caverns: %ld\n",
  79.     (long) c[GOLD],
  80.     (long) c[EXPERIENCE],
  81.     (long) c[LEVEL],
  82.     level);
  83.  
  84.     fprintf(dfile, "\nFor the c[] array:\n");
  85.     fflush(dfile);
  86.  
  87.     for( j=0; j<100; j++)
  88.         fprintf(dfile, "c[%d]\t%-20s\t= %ld\n", j, cdef[j], c[j]);
  89.     fprintf(dfile, "\n\n");
  90.     fflush(dfile);
  91.  
  92.     fprintf(dfile, "Inventory\n");
  93.     for (j=0; j<26; j++) {
  94.         fprintf (dfile, "iven[%d] %-12s = %d", 
  95.         j, ivendef[iven[j]], iven[j] );
  96.         fprintf (dfile, "\t%s", objectname[iven[j]] );
  97.         fprintf (dfile, "\t+ %d\n", ivenarg[j] );
  98.     }
  99.  
  100.     fprintf(dfile, "\nHere are the maps:\n\n");
  101.     monstnamelist[DEMONLORD] = '1';
  102.     monstnamelist[DEMONLORD+1] = '2';
  103.     monstnamelist[DEMONLORD+2] = '3';
  104.     monstnamelist[DEMONLORD+3] = '4';
  105.     monstnamelist[DEMONLORD+4] = '5';
  106.     monstnamelist[DEMONLORD+5] = '6';
  107.     monstnamelist[DEMONLORD+6] = '7';
  108.     monstnamelist[DEMONPRINCE] = '9';
  109.     monstnamelist[LUCIFER] = '0';
  110.     i = level;
  111.     for (j = 0; j <= MAXLEVEL+MAXVLEVEL-1; j++) {
  112.         newcavelevel(j);
  113.         fprintf(dfile, "\n-------------------------------------------------------------------\n");
  114.         fprintf(dfile, "Map %s    level %d\n", 
  115.         levelname[level], level);
  116.         fprintf(dfile, "-------------------------------------------------------------------\n");
  117.         diagdrawscreen();
  118.         fflush(dfile);
  119.     }
  120.     level = i;
  121.     getlevel();
  122.  
  123.     fprintf(dfile, "\n\nNow for the monster data:\n\n");
  124.     fprintf(dfile, "\nTotal types of monsters: %d\n\n", MAXMONST + 8);
  125.     fprintf(dfile, "   Monster Name      LEV  AC   DAM  ATT  DEF    GOLD   HP     EXP\n");
  126.     fprintf(dfile, "-----------------------------------------------------------------\n");
  127.     fflush(dfile);
  128.  
  129.     for (i = 0; i <= MAXMONST + 8; i++) {
  130.         fprintf(dfile, "%19s  %2d  %3d ", 
  131.         monster[i].name, 
  132.         monster[i].level, 
  133.         monster[i].armorclass);
  134.         fprintf(dfile, " %3d  %3d  %3d  ", 
  135.         monster[i].damage, 
  136.         monster[i].attack, 
  137.         monster[i].defense);
  138.         fprintf(dfile, "%6d  %3d   %6ld\n", 
  139.         monster[i].gold, 
  140.         monster[i].hitpoints,
  141.         (long) monster[i].experience);
  142.         fflush(dfile);
  143.     }
  144.  
  145.     fprintf(dfile, "\nAvailable potions:\n\n");
  146.     for (i = 0; i < MAXPOTION; i++)
  147.         fprintf(dfile, "%20s\n", &potionname[i][1]);
  148.     fflush(dfile);
  149.  
  150.     fprintf(dfile, "\nAvailable scrolls:\n\n");
  151.     for (i = 0; i < MAXSCROLL; i++)
  152.         fprintf(dfile, "%20s\n", &scrollname[i][1]);
  153.     fflush(dfile);
  154.  
  155.     fprintf(dfile, "\nSpell list:\n\n");
  156.     fprintf(dfile, "spell#  name           description\n");
  157.     fprintf(dfile, "-------------------------------------------------\n\n");
  158.  
  159.     for (j = 0; j < SPNUM; j++) {
  160.         fprintf(dfile, "%-10s", spelcode[j]);
  161.         fprintf(dfile," %21s\n", spelname[j]);
  162.         fprintf(dfile,"%s\n", speldescript[j]);
  163.     }
  164.     fflush(dfile);
  165.  
  166.     fprintf(dfile, "\nObject list\n\n");
  167.     fprintf(dfile, "\nj \tObject \tName\n");
  168.     fprintf(dfile, "---------------------------------\n");
  169.     for (j = 0; j < MAXOBJ; j++)
  170.         fprintf(dfile, "%d \t%c \t%s\n",
  171.         j,
  172.         objnamelist[j],
  173.         objectname[j] );
  174.     fflush(dfile);
  175.  
  176.     fprintf(dfile,"\n-------- End of DIAG diagnostics ---------\n");
  177.     fflush(dfile);
  178.     fclose(dfile);
  179.  
  180.     lprcat("\nDone Diagnosing.\n");
  181.     lflush();
  182.     return(0);
  183. }
  184.  
  185.  
  186. /*
  187.     draw the whole screen
  188.  */
  189. diagdrawscreen()
  190. {
  191.     register int    i, j, k;
  192.  
  193.     /* east west walls of this line    */
  194.     for (i = 0; i < MAXY; i++) {            
  195.         for (j = 0; j < MAXX; j++)
  196.             if (k = mitem[j][i])
  197.                 fprintf(dfile, "%c", monstnamelist[k]);
  198.             else
  199.                 fprintf(dfile, "%c", objnamelist[item[j][i]]);
  200.         fprintf(dfile, "\n");
  201.     }
  202. }
  203. /*
  204.     to save the game in a file
  205.  */
  206. static long int zzz=0;
  207. savegame(fname)
  208. char *fname;
  209. {
  210.     register int i,k;
  211.     register struct sphere *sp;
  212.     struct stat statbuf;
  213.  
  214.     nosignal=1;  
  215.     lflush();    
  216.     savelevel();
  217.     ointerest();
  218.     if (lcreat(fname) < 0) {
  219.         lcreat((char*)0); 
  220.         lprintf("\nCan't open file <%s> to save game\n",fname);
  221.         nosignal=0;  
  222.         return(-1);
  223.     }
  224.  
  225.     set_score_output();
  226.     lwrite((char*)beenhere,MAXLEVEL+MAXVLEVEL);
  227.     for (k=0; k<MAXLEVEL+MAXVLEVEL; k++)
  228.         if (beenhere[k])
  229.             lwrite((char*)&cell[k*MAXX*MAXY],sizeof(struct cel)*MAXY*MAXX);
  230.     lwrite((char*)&c[0],100*sizeof(long));
  231.     lprint((long)gtime);        
  232.     lprc(level);
  233.     lprc(playerx);        
  234.     lprc(playery);
  235.     lwrite((char*)iven,26);    
  236.     lwrite((char*)ivenarg,26*sizeof(short));
  237.     lwrite((char*)char_class,20);    
  238.     for (k=0; k<MAXSCROLL; k++)  lprc(scrollname[k][0]);
  239.     for (k=0; k<MAXPOTION; k++)  lprc(potionname[k][0]);
  240.     lwrite((char*)spelknow,SPNUM);         
  241.     lprc(wizard);
  242.     lprc(rmst);        /*    random monster generation counter */
  243.     for (i=0; i<90; i++)    lprc(itm[i].qty);
  244.     lwrite((char*)course,25);            
  245.     lprc(cheat);        
  246.  
  247.     /* genocide info */
  248.     for (i=0; i<MAXMONST; i++) lprc(monster[i].genocided);
  249.  
  250.     /* save spheres of annihilation */
  251.     for (sp=spheres; sp; sp=sp->p)
  252.         lwrite((char*)sp,sizeof(struct sphere));    
  253.  
  254.     time(&zzz);            
  255.     lprint((long)(zzz-initialtime));
  256.     lwrite((char*)&zzz,sizeof(long));
  257.  
  258.     if (fstat(lfd,&statbuf)< 0) lprint(0L);
  259.     else 
  260.         lprint((long)statbuf.st_ino); /* inode # */
  261.  
  262.     lwclose();    
  263.     lastmonst[0] = 0;
  264.     lcreat((char*)0);  
  265.     nosignal=0;
  266.     return(0);
  267. }
  268.  
  269. restoregame(fname)
  270. char *fname;
  271. {
  272.     register int i,k;
  273.     register struct sphere *sp,*sp2;
  274.     struct stat filetimes;
  275.  
  276.     cursors(); 
  277.     lprcat("\nRestoring . . .");  
  278.     lflush();
  279.     if (lopen(fname) <= 0) {
  280.         lcreat((char*)0); 
  281.         lprintf("\nCan't open file <%s> to restore game\n",fname);
  282.         nap(2000); 
  283.         c[GOLD]=c[BANKACCOUNT]=0;  
  284.         died(-265); 
  285.         return;
  286.     }
  287.  
  288.     lrfill((char*)beenhere,MAXLEVEL+MAXVLEVEL);
  289.     for (k=0; k<MAXLEVEL+MAXVLEVEL; k++)
  290.         if (beenhere[k])
  291.             lrfill((char*)&cell[k*MAXX*MAXY],sizeof(struct cel)*MAXY*MAXX);
  292.  
  293.     lrfill((char*)&c[0],100*sizeof(long));    
  294.     gtime = lrint();
  295.     level = c[CAVELEVEL] = lgetc();
  296.  
  297.     playerx = lgetc();        
  298.     playery = lgetc();
  299.  
  300.     lrfill((char*)iven,26);
  301.     lrfill((char*)ivenarg,26*sizeof(short));
  302.     lrfill((char*)char_class,20);        
  303.  
  304.     for (k=0; k<MAXSCROLL; k++)  scrollname[k][0] = lgetc();
  305.     for (k=0; k<MAXPOTION; k++)  potionname[k][0] = lgetc();
  306.  
  307.     lrfill((char*)spelknow,SPNUM);        
  308.  
  309.     wizard = lgetc();
  310.     rmst = lgetc();            /*    random monster creation flag */
  311.  
  312.     for (i=0; i<90; i++)    
  313.         itm[i].qty = lgetc();
  314.  
  315.     lrfill((char*)course,25);            
  316.     cheat = lgetc();
  317.  
  318.     /* genocide info */
  319.     for (i=0; i<MAXMONST; i++) monster[i].genocided=lgetc(); 
  320.  
  321.     for (sp=0,i=0; i<c[SPHCAST]; i++) {
  322.         sp2 = sp;
  323.         sp = (struct sphere *)malloc(sizeof(struct sphere));
  324.         if (sp==0) { 
  325.             fprintf(stderr, "Can't malloc() for sphere space\n"); 
  326.             break; 
  327.         }
  328.         /* get spheres of annihilation */
  329.         lrfill((char*)sp,sizeof(struct sphere));    
  330.         sp->p=0;    /* null out pointer */
  331.         if (i==0) spheres=sp;    /* beginning of list */
  332.         else sp2->p = sp;
  333.     }
  334.  
  335.  
  336.     time(&zzz);
  337.     initialtime = zzz-lrint();
  338.  
  339.     fstat(fd,&filetimes);/*get the creation and modification time of file*/
  340.  
  341.     lrfill((char*)&zzz,sizeof(long));    
  342.  
  343.     zzz += 6;
  344.     if (filetimes.st_ctime > zzz) 
  345.         fsorry();    /*file create time    */
  346.     else if (filetimes.st_mtime > zzz) 
  347.         fsorry(); /*    file modify time*/
  348.  
  349.  
  350.     if (c[HP]<0) { 
  351.         died(284); 
  352.         return; 
  353.     }    /* died a post mortem death */
  354.  
  355.     oldx = oldy = 0;
  356.  
  357.     i = lrint();  /* inode # */
  358.     if (i && (filetimes.st_ino!=i)) 
  359.         fsorry();    /* different inode number, file was copied */
  360.  
  361.     lrclose();
  362.  
  363.     if (strcmp(fname,ckpfile) == 0) {
  364.         if (lappend(fname) < 0) 
  365.             fcheat();  
  366.         else { 
  367.             lprc(' '); 
  368.             lwclose(); 
  369.         }
  370.         lcreat((char*)0);
  371.     }
  372.     else if (unlink(fname) < 0) 
  373.         fcheat(); /* can't unlink save file */
  374.  
  375.     /*    for the greedy cheater checker    */
  376.     /* for (k=0; k<6; k++) if (c[k]>99) greedy();
  377.     if (c[HPMAX]>999 || c[SPELLMAX]>125) greedy(); */
  378.     if (c[LEVEL]==25 && c[EXPERIENCE]>skill[24]) {
  379.         long tmp = c[EXPERIENCE]-skill[24]; /* amount to go up */
  380.         c[EXPERIENCE] = skill[24];
  381.         raiseexperience((long)tmp);
  382.     }
  383.     getlevel();  
  384.     lasttime=gtime;
  385.  
  386.     for (k=0; k<26; k++) 
  387.         if (iven[k] == OLARNEYE) {
  388.             monstnamelist[DEMONLORD] = '1';
  389.             monstnamelist[DEMONLORD+1] = '2';
  390.             monstnamelist[DEMONLORD+2] = '3';
  391.             monstnamelist[DEMONLORD+3] = '4';
  392.             monstnamelist[DEMONLORD+4] = '5';
  393.             monstnamelist[DEMONLORD+5] = '6';
  394.             monstnamelist[DEMONLORD+6] = '7';
  395.             monstnamelist[DEMONPRINCE] = '9';
  396.             monstnamelist[LUCIFER] = '0';
  397.             break;
  398.         }
  399. }
  400.  
  401. /*
  402.     subroutine to not allow greedy cheaters
  403.  */
  404. greedy()
  405. {
  406.     if (wizard) return;
  407.  
  408. lprcat("\n\nI am so sorry, but your character is a little TOO good!  Since this\n");
  409. lprcat("cannot normally happen from an honest game, I must assume that you cheated.\n");
  410. lprcat("In that you are GREEDY as well as a CHEATER, I cannot allow this game\n");
  411.     lprcat("to continue.\n"); 
  412.     nap(5000);  
  413.     c[GOLD]=c[BANKACCOUNT]=0;  
  414.     died(-267); 
  415.     return;
  416. }
  417.  
  418. /*
  419.     subroutine to not allow altered save files and terminate the attempted
  420.     restart
  421.  */
  422. fsorry()
  423. {
  424.     if(cheat) return;
  425. lprcat("\nSorry, but your savefile has been altered.\n");
  426. lprcat("However, seeing as I am a good sport, I will let you play.\n");
  427. lprcat("Be advised though, you won't be placed on the scoreboard.");
  428.     cheat = 1;    
  429.     nap(4000);
  430. }
  431.  
  432. /*
  433.     subroutine to not allow game if save file can't be deleted
  434.  */
  435. fcheat()
  436. {
  437.     if (wizard) return;
  438.     if(cheat) return;
  439.  
  440. lprcat("\nSorry, but your savefile can't be deleted.  This can only mean\n");
  441. lprcat("that you tried to CHEAT by protecting the directory the savefile\n");
  442. lprcat("is in.  Since this is unfair to the rest of the Ularn community, I\n");
  443. lprcat("cannot let you play this game.\n");
  444.     nap(5000);  
  445.     c[GOLD]=c[BANKACCOUNT]=0;  
  446.     died(-268); 
  447.     return;
  448. }
  449.